<!-- dictionary表单弹窗 -->
<form id="dictionary-form" lay-filter="dictionary-form" class="layui-form model-form">
    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">字典类型</label>
        <div class="layui-input-block">
            <input name="dictType" placeholder="请输入字典类型" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">字典编码</label>
        <div class="layui-input-block">
            <input name="dictCode" placeholder="请输入字典编码" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">中文名</label>
        <div class="layui-input-block">
            <input name="dictNameCn" placeholder="请输入中文名" type="text" class="layui-input" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">英文名</label>
        <div class="layui-input-block">
            <input name="dictNameEn" placeholder="请输入英文名" type="text" class="layui-input"
                   required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">顺序</label>
        <div class="layui-input-block">
            <input name="sort" placeholder="请输入顺序" type="text" class="layui-input" lay-verify="required|number"
                   required/>
        </div>
    </div>
    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" id="dictionary-form-submit" lay-filter="dictionary-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'admin', 'form', 'formSelects'], function () {
        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;
        var formSelects = layui.formSelects;

        var dictionary = admin.getTempData('t_dictionary');
        var operate = admin.getTempData('t_operate');
        $('#dictionary-form').attr('method', 'POST');
        if (dictionary) {
            form.val('dictionary-form', dictionary);
            $("input[name='dictType']").attr('disabled',true);
            $("input[name='dictType']").attr('class',"layui-input layui-disabled");
            $("input[name='dictCode']").attr('disabled',true);
            $("input[name='dictCode']").attr('class',"layui-input layui-disabled");
        }
        if(operate){
            // $("#dictionary-form-submit").attr("style","display:none;");
            $("#dictionary-form-submit").hide();
        }
        // 表单提交事件
        form.on('submit(dictionary-form-submit)', function (data) {
            layer.load(2);
            admin.req(api_user_context + 'dictionary/Dictionary', JSON.stringify(data.field), function (data) {
                layer.closeAll('loading');
                if (data.resp_code == 0) {
                    layer.msg(data.resp_msg, {icon: 1, time: 500});
                    admin.finishPopupCenter();
                } else {
                    layer.msg(data.resp_msg, {icon: 2, time: 500});
                }
            }, "POST");
            return false;
        });
    });
</script>